package org.qingke.mail.user.service.provider;

import org.qingke.mail.common.SearchProperty;
import org.qingke.mail.common.ServerResponse;
import org.qingke.mail.domain.TbUser;
import org.qingke.mail.mapper.TbUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户服务实现
 * @author JAVA
 *
 */
@Service("userServer")
public class UserServiceProvider implements UserService {

	@Autowired
	private TbUserMapper userMapper;
	
	@Override
	public ServerResponse insert(TbUser user) {
		
		int modify = userMapper.insert(user);
		
		ServerResponse response = ServerResponse.getInstance();
		boolean state = modify > 0;
		if(state){
			response.setState(true);
			response.setMessage("insert success");
		}else{
			response.setState(false);
			response.setMessage("insert fail");
		}
		return response;
	}

	@Override
	public ServerResponse queryByProperty(SearchProperty searchProperty) {
		ServerResponse response=ServerResponse.getInstance();
		TbUser user=userMapper.queryByProperty(searchProperty);
		if(null!=user){
			response.setState(true);
			response.setData(user);
		}else{
			response.setState(false);
			response.setMessage("user not exists");
		}
		return response;
	}

}
